package com.songhq.data.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.songhq.data.bean.Sect;
import com.songhq.data.bean.PageVO;
import com.songhq.data.mapper.SectMapper;
import com.songhq.data.utils.UUIDUtils;

@Service
public class SectService {
	
	
	@Autowired
	private SectMapper sectMapper;

	public PageVO listSects(Sect sect) {
		//使用分页查询helper
		PageHelper.startPage(sect.getPageNumber(), sect.getPageSize());
		//执行查询
		List<Sect> list = sectMapper.listSect(sect);
		//创建一个返回值对象
		PageVO<Sect> pageBean = new PageVO<Sect> ();
		pageBean.setList(list);
		//取分页结果
		PageInfo<Sect> pageInfo = new PageInfo<>(list);
		//取总记录数
		long total = pageInfo.getTotal();
		pageBean.setCount(total);
		return pageBean;
	}

	public Sect getOneSect(String sectId) {
		
		Sect sect = sectMapper.getOneSect(sectId);
		return sect;
	}

	public void saveSect(Sect sect) {
		String sectId = UUIDUtils.generateUUID();
		sect.setSectId(sectId);
		sectMapper.insert(sect);
	}

	public void updateSect(Sect sect) {
		
		sectMapper.updateSect(sect);
		
	}

	public void deleteSect(Sect sect) {
		
		sectMapper.deleteSect(sect);
	}
	

}
